In [1]:
using Symata

Differences from Wolfram / Mathematica

Symata is similar to the Wolfram language. But, there are difference in notation and behavior.

Multiplication

In Symata, multiplication of a number and variable does not require the * symbol. But space between the number and variable is not allowed. All other multiplications requires an explicit *.


In [2]:
[2x + 1, 2 * x + 1, 2 * 3, Cos(x) * Sin(x)]


Out[2]:
$$ \left[ 1 + 2 \ x,1 + 2 \ x,6,\text{Cos} \! \left( x \right) \ \text{Sin} \! \left( x \right) \right] $$

Comments

In Symata, comments are entered with the prefix #. In Mathematica, comments are entered like this (* comment *)


In [3]:
# a = 1
  b = 2

[a,b]


Out[3]:
$$ \left[ a,2 \right] $$

List

Mathematica lists are delimited by { }. Symata lists are delimited by [ ]


In [4]:
[a,b,c]


Out[4]:
$$ \left[ a,2,c \right] $$

Curly braces may also be used to enter lists in Symata. This may change in the future.


In [5]:
{a,b,c}


Out[5]:
$$ \left[ a,2,c \right] $$

Elements in a list may be separated by commas, as above. But, in Symata they may also be separated by a newline after a complete expression.


In [6]:
[
    a
    c + d
    "cat"
    Expand((x+y)^2)
]


Out[6]:
$$ \left[ a,c + d,\text{"cat"},x^{2} + 2 \ x \ y + y^{2} \right] $$

Functions

Function arguments are delimited by [ ] in Mathematica. In Symata, arguments are delimited by ( )


In [7]:
f(x)


Out[7]:
$$ f \! \left( x \right) $$

Compound expressions

There are several ways to enter compound expressions.


In [8]:
e1 = (1,2,a+b)

e2 = (1,
      2,
      a+b)


e3  = begin
     1
     2
    a+b
end

e1 == e2 == e3


Out[8]:
$$ \text{True} $$

Infix notation for Map, Apply, Rule, ReplaceAll, etc.

Map


In [9]:
f % list


Out[9]:
$$ \text{Map} \! \left( f,list \right) $$

In [10]:
f % [a,b,c]


Out[10]:
$$ \left[ f \! \left( a \right) ,f \! \left( 2 \right) ,f \! \left( c \right) \right] $$

Apply


In [11]:
x .%  y


Out[11]:
$$ \text{Apply} \! \left( x,y \right) $$

In [12]:
f .% g(1,2)


Out[12]:
$$ f \! \left( 1,2 \right) $$

In [ ]:

Rule

Rule can be entered in the following ways. The symbol ⇒ can be entered with \Rightarrow[TAB]


In [13]:
[Rule(a,b), a => b , a  b]


Out[13]:
$$ \left[ a \Rightarrow 2,a \Rightarrow 2,a \Rightarrow 2 \right] $$

RuleDelayed


In [14]:
[RuleDelayed(a,b),  a .> b]


Out[14]:
$$ \left[ a\text{:>}b,a\text{:>}b \right] $$

ReplaceAll

The short "infix" symbol for ReplaceAll is ./. In Mathematica, it is /.. Also note the parentheses surrounding the rule.


In [15]:
[a, x^2, b^3, (a+b)^3]  ./ ( x_^n_ => g([n],x))


Out[15]:
$$ \left[ a,g \! \left( \left[ 2 \right] ,x \right) ,8,g \! \left( \left[ 3 \right] ,2 + a \right) \right] $$

Patterns

Blank

x_ is a blank matching a single element. y__ is a blank sequence, matching one or more elements


In [16]:
f(x_, y__) := [x,[y]]
f(1,[2,3,4])


Out[16]:
$$ \left[ 1, \left[ \left[ 2,3,4 \right] \right] \right] $$

Repeated

In Mathematica, Repeated[a] is denoted by a... In Symata, Repeated(a) is denoted by a.... Notice that in Symata, there are three dots instead of two.


In [17]:
[
MatchQ([a,a,b,(a+b)^3,c,c,c], [a..., b, _^3... , c...])
MatchQ([a,a,(a+b)^3,c,c,c], [a..., b, _^3... , c...])
]


Out[17]:
$$ \left[ \text{True},\text{False} \right] $$

Repeated can be used in operator form.


In [18]:
ClearAll(f)
f(x_...) := x

In [19]:
f(3,3,3,3)


Out[19]:
$$ 3 $$

In Mathematica, Repeated[expr,n] matches at least n occurences of expr. In Symata, Repeated(expr,n) does the same.


In [20]:
[
    MatchQ([1,2,3], [Repeated(_Integer,2)])
    MatchQ([1,2,3], [Repeated(_Integer,3)])
]


Out[20]:
$$ \left[ \text{False},\text{True} \right] $$

RepeatedNull

In Symata RepeatedNull must be written in full form. (We have not yet chosen a symbol for it)


In [21]:
MatchQ([], [RepeatedNull(_Integer)])


Out[21]:
$$ \text{True} $$

As in Mathematica, default values of optional arguments are specified using :.


In [22]:
ClearAll(fa,b)

f(x_, y_:a, z_:b) := [x,y,z]

[
 f(1) == [1,a,b]
 f(1,2) == [1,2,b]
 f(1,2,3) == [1,2,3]
]


Out[22]:
$$ \left[ 1\text{==} \left[ 1,a,b \right] ,\text{True},\text{True} \right] $$

Named compound Patterns

In Mathematica, names for complex patterns use a colon a:(b_^c_). In Symata, use two colons.


In [23]:
ClearAll(g,a,b)

b^b  ./  ( a::(_^_) => g(a) )


Out[23]:
$$ g \! \left( b^{b} \right) $$

PatternTest

In Mathematica, PatternTest is given like this p_?PrimeQ. In Symata use :? and parentheses.


In [24]:
countprimes = Count(_:?(PrimeQ))
countprimes(Range(100))


Out[24]:
$$ 25 $$

You can use a Julia function as the test.


In [25]:
p = _:?(J( x ->  -1 < x < 1 ))

[
MatchQ(0,p)
MatchQ(.5,p)
MatchQ(-1/2,p)
MatchQ(-1,p)
]


Out[25]:
$$ \left[ \text{True},\text{True},\text{True},\text{False} \right] $$

Alternatives

Alternatives is denoted by the vertical bar |.


In [26]:
ClearAll(f)

f(x_, x_ | y_String) := [x,y]

[ f(2,2) , f(2,"cat")]


Out[26]:
$$ \left[ \left[ 2 \right] , \left[ 2,\text{"cat"} \right] \right] $$

Condition

Condition must be written in full form.


In [27]:
[
MatchQ( -2 , Condition( x_ , x < 0))
MatchQ(  2 , Condition( x_ , x < 0))
]


Out[27]:
$$ \left[ \text{True},\text{False} \right] $$

In [28]:
ClearAll(y)

ReplaceAll([1,2,3, "cat"], x_Integer => Condition( y, x > 2))


Out[28]:
$$ \left[ 1,2,y,\text{"cat"} \right] $$

In [29]:
ClearAll(f)

f(x_) :=  Condition(x^2, x > 3)

[f(2),f(4)]


Out[29]:
$$ \left[ f \! \left( 2 \right) ,16 \right] $$